package org.pp.controller;


import io.swagger.v3.oas.annotations.Operation;
import org.pp.core.Result;
import org.pp.service.IPpCategorizeService;
import org.pp.service.IPpGoodsService;
import org.pp.vo.MiniappCategorizeVo;
import org.pp.vo.MiniappGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/categorize")
public class PpGoodsCategorizeController {

    @Autowired
    IPpCategorizeService categorizeService;

    @Autowired
    IPpGoodsService  goodsService;

    @GetMapping("/nav")
    @Operation(summary = "导航分类")
    public Result<List<MiniappCategorizeVo>> getNavCate(){
        return Result.ok(categorizeService.getNavCate());
    }

    @GetMapping("/list")
    @Operation(summary = "查询分类列表")
    public Result<List<MiniappCategorizeVo>> getList(@RequestParam(name = "type") Integer type){
        return Result.ok(categorizeService.getList(type));
    }

    @GetMapping("/goods")
    @Operation(summary = "查询分类的商品")
    public Result<List<MiniappGoodsVo>> getGoodsByCateId(@RequestParam(name = "cateId",required = true) Long cateId){
        return Result.ok(goodsService.getGoodsByCateId(cateId));
    }
}
